package com.example.mylibrary;

import static android.content.ContentValues.TAG;

import android.app.Instrumentation;
import android.util.Log;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class BarterReleaselose {
    public static UiDevice device;
    public static Instrumentation instrumentation;

    @Before
    public void first() throws InterruptedException {
        Log.i(TAG, "连接设备");
        instrumentation =
                InstrumentationRegistry.getInstrumentation();
        device = UiDevice.getInstance(instrumentation);
        int width = device.getDisplayWidth();
        int height = device.getDisplayHeight();
        device.pressHome();
        Thread.sleep(2000);
        device.swipe(width - 10, height / 2, 50, height / 2, 10);
        Thread.sleep(2000);
        UiObject2 barter = device.findObject(By.text("Barter"));
        barter.click();
        Thread.sleep(3000);
    }
//    价格框无法输入字母
    @Test
    private void Release17() throws InterruptedException {
        Thread.sleep(1000);
//    注册
        device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
                click();
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
                click();
        Thread.sleep(1000);
//    登录
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
                setText("2019012510");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
                setText("123456");
        Thread.sleep(1000);
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
                click();
        Thread.sleep(1000);
//    发布闲置
        device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
        Thread.sleep(1000);
//    添加照片
        device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
        device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
        Thread.sleep(1000);
//    输入标题
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_title")).setText("学习用品1");
        Thread.sleep(1000);
//    选择类别
        device.findObject(By.res("请选择类别")).click();
        Thread.sleep(1000);
        device.findObject(By.res("学习用品")).click();
        Thread.sleep(1000);
//    输入价格
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("yibai");
        Thread.sleep(1000);
//    输入联系方式
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("18875741673");
        Thread.sleep(1000);
//    简单描述产品
        device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("这是学习用品");
        Thread.sleep(1000);
//        点击发布
        device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
        Thread.sleep(1000);
    }
//    价格框无法输入汉字
@Test
private void Release18() throws InterruptedException {
    Thread.sleep(1000);
//    注册
    device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
            click();
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
            setText("2019012510");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
            click();
    Thread.sleep(1000);
//    登录
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
            setText("2019012510");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
            click();
    Thread.sleep(1000);
//    发布闲置
    device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
    Thread.sleep(1000);
//    添加照片
    device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
    Thread.sleep(1000);
    device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
    Thread.sleep(1000);
    device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
    Thread.sleep(1000);
//    输入标题
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_title")).setText("学习用品1");
    Thread.sleep(1000);
//    选择类别
    device.findObject(By.res("请选择类别")).click();
    Thread.sleep(1000);
    device.findObject(By.res("学习用品")).click();
    Thread.sleep(1000);
//    输入价格
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("一百");
    Thread.sleep(1000);
//    输入联系方式
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("18875741673");
    Thread.sleep(1000);
//    简单描述产品
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("这是学习用品");
    Thread.sleep(1000);
//        点击发布
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
    Thread.sleep(1000);
}
// 联系方式格式输入失败
@Test
private void Release19() throws InterruptedException {
    Thread.sleep(1000);
//    注册
    device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
            click();
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
            setText("2019012510");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
            click();
    Thread.sleep(1000);
//    登录
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
            setText("2019012510");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
            click();
    Thread.sleep(1000);
//    发布闲置
    device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
    Thread.sleep(1000);
//    添加照片
    device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
    Thread.sleep(1000);
    device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
    Thread.sleep(1000);
    device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
    Thread.sleep(1000);
//    输入标题
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_title")).setText("学习用品1");
    Thread.sleep(1000);
//    选择类别
    device.findObject(By.res("请选择类别")).click();
    Thread.sleep(1000);
    device.findObject(By.res("学习用品")).click();
    Thread.sleep(1000);
//    输入价格
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("100");
    Thread.sleep(1000);
//    输入联系方式-少输入一位号码
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("1887574167");
    Thread.sleep(1000);
//    简单描述产品
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("这是学习用品");
    Thread.sleep(1000);
//        点击发布
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
    Thread.sleep(1000);
}
// 网络连接失败
@Test
private void Release20() throws InterruptedException {
    Thread.sleep(1000);
//    注册
    device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
            click();
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
            setText("2019012510");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
            click();
    Thread.sleep(1000);
//    登录
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
            setText("2019012510");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
            click();
    Thread.sleep(1000);
//    发布闲置
    device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
    Thread.sleep(1000);
//    添加照片
    device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
    Thread.sleep(1000);
    device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
    Thread.sleep(1000);
    device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
    Thread.sleep(1000);
//    输入标题
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_title")).setText("学习用品1");
    Thread.sleep(1000);
//    选择类别
    device.findObject(By.res("请选择类别")).click();
    Thread.sleep(1000);
    device.findObject(By.res("学习用品")).click();
    Thread.sleep(1000);
//    输入价格
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("100");
    Thread.sleep(1000);
//    输入联系方式
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("18875741673");
    Thread.sleep(1000);
//    简单描述产品
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("这是学习用品");
    Thread.sleep(1000);
//        点击发布
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
    Thread.sleep(1000);
//    发布失败提示无网络
}
//发布页面不显示发布信息
@Test
private void Release21() throws InterruptedException {
    Thread.sleep(1000);
//    注册
    device.findObject(By.res("com.leaf.collegeidleapp:id/tv_register")).
            click();
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
            setText("2019012510");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_confirm_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_register")).
            click();
    Thread.sleep(1000);
//    登录
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_username")).
            setText("2019012510");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_password")).
            setText("123456");
    Thread.sleep(1000);
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_login")).
            click();
    Thread.sleep(1000);
//    发布闲置
    device.findObject(By.res("com.leaf.collegeidleapp:id/ib_add_product")).click();
    Thread.sleep(1000);
//    添加照片
    device.findObject(By.res("com.leaf.collegeidleapp:id/iv_photo")).click();
    Thread.sleep(1000);
    device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
    Thread.sleep(1000);
    device.findObject(By.res("com.android.gallery3d:id/gl_root_view")).click();
    Thread.sleep(1000);
//    输入标题
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_title")).setText("学习用品1");
    Thread.sleep(1000);
//    选择类别
    device.findObject(By.res("请选择类别")).click();
    Thread.sleep(1000);
    device.findObject(By.res("学习用品")).click();
    Thread.sleep(1000);
//    输入价格
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_price")).setText("100");
    Thread.sleep(1000);
//    输入联系方式
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_phone")).setText("18875741673");
    Thread.sleep(1000);
//    简单描述产品
    device.findObject(By.res("com.leaf.collegeidleapp:id/et_description")).setText("这是学习用品");
    Thread.sleep(1000);
//        点击发布
    device.findObject(By.res("com.leaf.collegeidleapp:id/btn_publish")).click();
    Thread.sleep(1000);
//    查看物品
    device.findObject(By.res("com.leaf.collegeidleapp:id/ib_learning_use")).click();
    Thread.sleep(1000);
//    刷新
    device.findObject(By.res("com.leaf.collegeidleapp:id/tv_refresh")).click();
//    仍无反应
}
    @After
    public static void tearDown() {
        device.pressBack();
    }
}
